﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using VersionComparer.UI.ExtendedRichTextBox;

namespace VersionComparer.UI.ExtendedTreeView
{
    public class ColorSyntaxEventArg : EventArgs
    {

        RichTextBoxColorInfoCollection colorInfos = new RichTextBoxColorInfoCollection();
        public ColorSyntaxEventArg(string text, int lineIndex, Color? suggestedColor)
        {
            Text = text;
            LineIndex = lineIndex;
        }
        public string Text
        {
            get;
            private set;
        }
        public int LineIndex
        {
            get;
            private set;
        }

        public RichTextBoxColorInfoCollection Colors
        {
            get
            {
                return colorInfos;
            }
            set
            {
                if (value == null)
                    value = new RichTextBoxColorInfoCollection();
                colorInfos = value;
            }
        }

        public void SetForeColor(Color foreColor)
        {
            if (colorInfos.Count == 0 || !colorInfos[0].IsFullLine)
            {
                colorInfos.Insert(0, new RichTextBoxColorInfo()
                {
                    ForeColor = foreColor
                });
            }
            else
            {
                colorInfos[0].ForeColor = foreColor;
            }
        }
        public void SetBackColor(Color backColor)
        {
            if (colorInfos.Count == 0 || !colorInfos[0].IsFullLine)
            {
                colorInfos.Insert(0, new RichTextBoxColorInfo()
                {
                    ForeColor = backColor
                });
            }
            else
            {
                colorInfos[0].BackColor = backColor;
            }
        }
        public void AddColor(int start, int end, Color? foreColor, Color? backColor)
        {
            AddColor(new RichTextBoxColorInfo()
            {
                Start = start,
                Length = end,
                ForeColor = foreColor,
                BackColor = backColor
            });
        }
        

        public void AddColor ( RichTextBoxColorInfo colorInfo)
        {
            colorInfos.Add(colorInfo);
        }
    }
}
